package com.anycc.cloud.common.dto.datatable;

import com.anycc.cloud.common.dto.query.PagingResponse;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * datatable response
 * @param <T> T
 */
@Data
public class DataTableResponse<T> {
    private Integer draw;
    private Integer recordsTotal;
    private Integer recordsFiltered;
    private List<T> data = new ArrayList<>();
    private String error;

    public DataTableResponse() {
    }

    public DataTableResponse(String error) {
        this.error = error;
    }

    public DataTableResponse(PagingResponse<T> dataPage, DataTableRequest request) {
        if (dataPage != null) {
            this.data = dataPage.getDatas();
            this.recordsTotal = (int)dataPage.getTotalElements();
            this.recordsFiltered = (int)dataPage.getTotalElements();
            this.draw = request.getDraw();
        }

    }
}
